﻿using Consul;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Text;

namespace order.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
        private readonly IConsulClient _consulClient;
        public OrderController(IConsulClient consulClient) {
            _consulClient = consulClient;
        }
        [HttpGet]
        public  ActionResult GetOrderInfoAsync() {
            var services =  _consulClient.Agent.Services().Result;
            
           var sc= services.Response.Select(x => new{key=x.Key,ServiceId=x.Value.ID,Address=x.Value.Address,Port=x.Value.Port,ServiceName=x.Value.Service}).ToList();
           
            return Ok(sc);
        }

        //获取 consul 配置
        [HttpGet("GetConfig")]
        public string GetConfig() {
            var x=_consulClient.KV.Get("bbc/myjson").Result;
          
            return Encoding.UTF8.GetString(x.Response.Value);
        }
        
    }
}
